package com.zdy.today.adapter;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zdy.model.HomeBean;
import com.zdy.today.R;
import com.zdy.utils.Utils;

import java.util.List;

/**
 * Created by zdy on 2016/9/19.
 */
public class HomeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<HomeBean> listBean;
    private FragmentActivity context;

    public HomeAdapter(Context context) {
        this.context = (FragmentActivity) context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // create a new view
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item_home, parent, false);
        // set the view's size, margins, paddings and layout parameters
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.tv_num.setText(" 序号：" + (position + 1) + " ");
        viewHolder.tv_number.setText(Utils.getOpenCode(listBean.get(position).getOpencode()));
        viewHolder.tv_time.setText("第" + listBean.get(position).getExpect() + "期\n" + "开奖：" + listBean.get(position).getOpentime());
    }

    @Override
    public int getItemCount() {
        if (listBean == null)
            return 0;
        return listBean.size();
    }

    public void setListBean(List<HomeBean> listBean) {
        this.listBean = listBean;
    }

    // Provide a reference to the views for each data item
    // Complex data items may need more than one view per item, and
    // you provide access to all the views for a data item in a view holder
    public static class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case

        public TextView tv_number;
        public TextView tv_num;
        public TextView tv_time;

        public ViewHolder(View v) {
            super(v);
            tv_number = (TextView) v.findViewById(R.id.tv_number);
            tv_num = (TextView) v.findViewById(R.id.tv_num);
            tv_time = (TextView) v.findViewById(R.id.tv_time);
        }
    }

}
